package com.g5kj.coupon.ssm.controller;

import com.g5kj.coupon.ssm.common.Result;
import com.g5kj.coupon.ssm.model.ArticleEntity;
import com.g5kj.coupon.ssm.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.portlet.ModelAndView;

import java.util.List;

/**
 * 文章.
 */
@RequestMapping(value = "/article")
@Controller
public class ArticleController {


    @Autowired
    ArticleService articleService;



    @RequestMapping(value = "/post",method = RequestMethod.POST)
    public @ResponseBody Result add(ArticleEntity params){
        return articleService.addArticle(params);
    }

    @RequestMapping(value = "/add")
    public String showAddView(){

        return "/article/add";

    }
    @RequestMapping(value = "")
    public String list(@RequestParam(value = "page",defaultValue = "1")int page,@RequestParam(value = "startTime",required = false) String startTime,
                       @RequestParam(value = "endTime",required = false)String lastTime, @RequestParam(value = "keyValue",required = false)String keyValue,
                       @RequestParam(value = "order",defaultValue = "create_time") String order,
                       @RequestParam(value = "sort",defaultValue = "0") int sort, ModelMap modelMap){

        List<ArticleEntity> res=articleService.list(page,startTime,lastTime,keyValue,order,sort);
        modelMap.put("list",res);
        return "/article/list";
    }

}
